<!--
* description: 车系编码弹窗（含输入框）
* author: ydche
* createdDate: 2019-11-6
*  2019-08-09 修改文字溢出效果-封装/校验效果 liyanm
-->

<template>
  <section
    class="carTypeConfig"
    v-show="curIsShow"
    :key="fullComponentKey"
  >
    <el-col :span="span">
      <lableName
      :style="span==12?'width:14%':''"
        :validrule="validrule"
        :curLabelName="curLabelName"
        :isShowLabel="isShowLabel"
        :isRequire="isRequire"
      ></lableName>
      <el-input
        :style="setInputWidth(span)"
        :placeholder="placeholder"
        v-model="modelCode"
        :disabled="disabled"
        size="small"
        suffix-icon="el-icon-menu"
        @clear="clearCode"
        clearable
        @blur="sendCode"
        @focus="getFocusCode"
      ></el-input>
      <validateFormate
        :curLabelName="curLabelName"
        :validrule="validrule"
      ></validateFormate>
    </el-col>
    <chooseSpareParts
      :popupsVisible="curPopupsVisible"
      :codeField="codeField"
      :textField="textField"
      :comType="comType"
      :valueObject="curValueObject"
      :popupsKey="popupsKey"
      :code="modelCode"
      :text="modelText"
      :key="curPopupsKey"
      :isMul="isMul"
      :returnCodeField="returnCodeField"
      :returnTextField="returnTextField"
      @changeCode="getComponentCode1"
      ref="dialogComponent"
    ></chooseSpareParts>
  </section>
</template>
<script>
import { searchInputMixins } from "@/components/mixins/searchInputMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
import { orgApis } from "@/api/apiList/org";
// import lableName from "@/components/lableName";
// import chooseSpareParts from "./selectCarSeries";
// import validateFormate from "@/components/validateFormate";
export default {
  // 组件混入对象
  mixins: [searchInputMixins, valueObjectMixins],
  components: {
    chooseSpareParts: () => import("./selectCarSeries"),
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate"), //校验提示样式组件
  },
  data() {
    return {
      placeholder: this.$t("sys.tips.esTip0"),
      curLabelName:
        this.labelName === "" ? this.$t("org.label.carConfig") : this.labelName
    };
  },
  methods: {
    // 重写显示时执行事件
    onShow() {
      var that = this;
      if (that.isColComp !== true) {
        var parent = that.$utils.getHasFormFieldParentComponent(that);
        if (
          parent.formField &&
          parent.formField.carBrandCode &&
          parent.formField.carBrandCode !== ""
        ) {
          // 赋值  （已经改为在父组件中使用watch监听赋值，parentFileds传值）
          //that.curValueObject.carBrandCode = parent.formField.carBrandCode;
          //that.curPopupsKey = that.codeField + that.$utils.generateId();
        }
        // else {
        //   that.$alert("请先选择品牌", "提示", {
        //     confirmButtonText: "确定",
        //     callback: action => {
        //       that.close();
        //     }
        //   });
        // }
      }
    },
    getComponentCode1(
      code,
      text,
      codeField,
      comType,
      popupsKey,
      textField,
      otherField,
      selectData
    ) {
      this.getComponentCode(
        code,
        text,
        codeField,
        comType,
        popupsKey,
        textField,
        otherField,
        selectData
      );
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      let results = selectData[0];
      for (let key in parent.formField) {
        if (results.hasOwnProperty(key)) {
          parent.formField[key] = results[key];
        }
      }
      this.$emit("emitCode", selectData);
    },
    setInputWidth(span) {
      switch (span) {
        case 6:
          return "";
        case 12:
          return "width:85%;line-height: 38px;";
      }
    }
  }
};
</script>
